import { createRouter, createWebHashHistory } from 'vue-router'
import { useUserStore } from '@/pinia/modules/user'
const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/view/login/index.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('@/view/home/index.vue')
  },
  {
    path: '/my',
    name: 'my',
    component: () => import('@/view/my/index.vue')
  },
  {
    path: '/page1',
    name: 'page1',
    component: () => import('@/view/demos/page1.vue')
  },
  {
    path: '/:catchAll(.*)',
    hidden: true,
    component: () => import('@/view/error/index.vue')
  },
  {
    path: '/orgBed',
    name: '机构轮候床位使用率总体情况',
    component: () => import('@/view/org-bed/index.vue')
  },
  {
    path: '/serviceFacility',
    name: '社区居家养老服务项目设施总体情况',
    component: () => import('@/view/service-facility/index.vue')
  },
  {
    path: '/elderDistribution',
    hidden: true,
    component: () => import('@/view/elderDistribution/index.vue')
  },
  {
    path: '/elderDistributionArea',
    hidden: true,
    component: () => import('@/view/elderDistribution/area.vue')
  },
  {
    path: '/pension',
    hidden: true,
    component: () => import('@/view/pension/index.vue')
  },
  {
    path: '/pensionArea',
    hidden: true,
    component: () => import('@/view/pension/area.vue')
  },
  {
    path: '/subsidy',
    hidden: true,
    component: () => import('@/view/subsidy/index.vue')
  },
  {
    path: '/subsidyArea',
    hidden: true,
    component: () => import('@/view/subsidy/area.vue')
  },
  {
    path: '/personnel',
    hidden: true,
    component: () => import('@/view/personnel/index.vue')
  },
  {
    path: '/personnelArea',
    hidden: true,
    component: () => import('@/view/personnel/area.vue')
  },
  {
    path: '/fund',
    hidden: true,
    component: () => import('@/view/fund/index.vue')
  },
  {
    path: '/fundArea',
    hidden: true,
    component: () => import('@/view/fund/area.vue')
  },
  {
    path: '/expert',
    hidden: true,
    component: () => import('@/view/expert/index.vue')
  },
  {
    path: '/expertArea',
    hidden: true,
    component: () => import('@/view/expert/area.vue')
  },
  {
    path: '/bedDistribution',
    hidden: true,
    name: '养老服务床位区域分布情况',
    component: () => import('@/view/bed-distribution/index.vue')
  },
  {
    path: '/startRating',
    hidden: true,
    name: '星级评定总体情况',
    component: () => import('@/view/start-rating/index.vue')
  },
  {
    path: '/ylfwss',
    name: '养老服务设施详情',
    component: () => import('@/view/org-detail/index.vue')
  },
  {
    path: '/timeBank',
    name: '时间银行积分总体情况',
    component: () => import('@/view/time-bank/index.vue')
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
      next()
  } else {
    if (useUserStore().userInfo) {
      next()
    } else {
      next('/login')
    }
  }})

export default router
